﻿
        function reloadGrid() {
            $('#tSortable').dataTable({
                "iDisplayLength": 5,
                "aLengthMenu": [5, 10, 25, 50, 100],
                "sPaginationType": "full_numbers",
                "iSortingCols": "STT"
            });
        }


        function Success(data)
        {
            if (data == "exist")
            {
                $.topAlertPopup({ "text": "The name of this item has existed", "typeAlert": "error" });
            }
            else
            {
                if (data != "") {
                    $.topAlertPopup({ "text": "Update completed", "typeAlert": "success" });
                    $('#ID').val(data.ID);
                    $('#Code').val(data.Code);
                    $('#Note').val(data.Note);
                    $('#Name').val(data.Name);
                    $(".chosen-select").val(data.UserID);
                    $("#PlanID").val(data.PlanID);
                    $("#Status").val(data.Status);
                    $("#Balance").val(data.Balance);
                    $("#RegisterDate").datetimepicker({ format: 'd/m/Y' });
                    $("#ActiveDate").datetimepicker({ format: 'd/m/Y' });
                    if (data.RegisterDate != "" && data.RegisterDate != null && data.ActiveDate != "" && data.ActiveDate != null) {
                        var register = new Date(parseInt(data.RegisterDate.substr(6)));
                        var formatteddregister = register.getFullYear() + "-" + ("0" + (register.getMonth() + 1)).slice(-2) + "-" + ("0" + register.getDate()).slice(-2);

                        var active = new Date(parseInt(data.ActiveDate.substr(6)));

                        var formattedactive = active.getFullYear() + "-" + ("0" + (active.getMonth() + 1)).slice(-2) + "-" + ("0" + active.getDate()).slice(-2);

                        $('#RegisterDate').datetimepicker('setDate', formatteddregister);
                        $('#ActiveDate').datetimepicker('setDate', formattedactive);
                    }

                    CKEDITOR.instances['Description'].setData(data.Description);

                    if (data.Active == false)
                    {
                        $('input[id=Active]').attr('checked', false);
                    }
                    else
                    {
                        $('input[id=Active]').attr('checked', true);
                    }
                   
                    $('#MetaTitle').val(data.MetaTitle);
                    $('#MetaKeyword').val(data.MetaKeyword);
                    $('#MetaDescription').val(data.MetaDescription);

                }
                else {
                    $.topAlertPopup({ "text": "Error , try again please !", "typeAlert": "error" });
                }
            }
        }


       
